const fs = require('fs');

//原生方式
// fs.readFile('./resource/1.html', (err, data) => {
//   if(err) throw err;
//   console.log(data.toString());
// })

//Promise
let p = new Promise((resolve, reject) => {
  fs.readFile('./resource/1.html', (err, data) => {
    //如果读取失败
    if(err){
      return reject(err);
    }
    //如果读取成功
    resolve(data);
  })
});

p.then(value => {
  console.log(value.toString());
}, reason => {
  console.log(reason.code);
})